package com.liruo.learn.spring.mvc.controller.valid;

import com.liruo.learn.spring.mvc.controller.valid.group.Add;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.util.ArrayList;

/**
 * @Author:liruo
 * @Date:2023-05-08-21:32:56
 * @Desc
 */
@Validated
@RestController
@Slf4j
@RequestMapping("/validated-on-class")
public class ValidatedController {
    /**
     * 不是校验集合里元素的意思, 用在分组上, 不同分组用不同错误信息
     */
    @GetMapping("/list")
    public void list(@NotEmpty.List({
            @NotEmpty(message = "1 can't null"),
            @NotEmpty(message = "2 can't null")
    }) ArrayList<String> listNotEmpty2) {
        log.info("list, {}", listNotEmpty2);
    }

    @GetMapping("/common")
    public void common(@NotNull String notNull, @NotBlank String notBlank, @NotEmpty String notEmpty, @NotEmpty ArrayList<String> listNotEmpty1) {
        log.info("common, {} {} {} {}", notNull, notBlank, notEmpty, listNotEmpty1);
    }
    @PostMapping("/bean")
    @Validated({Add.class, Default.class})
    public void bean(@Validated @RequestBody ValidBean validBean){
        log.info("bean {}", validBean);
    }
}

